<template>
  <div class="app-container">
    <el-form :inline="true" :model="listQuery" @submit.native.prevent>
      <el-form-item label="商家名称">
        <el-select v-model="listQuery.q_sellerId" size="small" placeholder="请选择">
          <el-option v-for="item in sellers" :label="item.sellerName" :key="item.id" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="购买人">
        <el-input v-model="listQuery.q_buyName" maxlength="50" size="small" class="filter-item" />
      </el-form-item>
      <el-form-item label="佣金状态">
        <el-select v-model="listQuery.q_saleState" size="small" placeholder="请选择">
          <el-option v-for="item in saleOrderStatus" :label="item.name" :key="item.value" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="small" type="primary" @click="check">查询</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table ref="singleTable" :data="dataList" border fit highlight-current-row v-loading="listLoading"
      style="width: 100%" @current-change="handleCurrentChange">
      <el-table-column type="index" align="center" width="50">
      </el-table-column>
      <el-table-column property="buyName" width="150" label="购买人"></el-table-column>
      <el-table-column property="memberName" width="150" label="拿分佣用户"></el-table-column>
      <el-table-column property="productName" width="400" label="商品名称" show-overflow-tooltip></el-table-column>
      <el-table-column property="sellerName" width="200" label="商家名称" show-overflow-tooltip></el-table-column>
      <el-table-column property="orderSn" width="200" label="订单号"></el-table-column>
      <el-table-column property="orderTime" width="200" label="下单日期"></el-table-column>
      <el-table-column property="moneyAll" width="150" label="总金额"></el-table-column>
      <el-table-column property="actMoney" width="150" label="优惠金额"></el-table-column>
      <el-table-column property="money" width="150" label="单价"></el-table-column>
      <el-table-column property="number" width="150" label="购买数量"></el-table-column>
      <el-table-column property="saleMoney" width="150" label="佣金金额"></el-table-column>
      <el-table-column property="saleScale" width="150" label="佣金比例"></el-table-column>
      <el-table-column property="saleState" width="200" label="佣金状态">
        <template slot-scope="scope">
          {{ codeBox.SALE_ORDER_STATE[scope.row.saleState] }}
        </template>
      </el-table-column>
      <el-table-column property="saleGrade" width="150" label="分佣级数"></el-table-column>
      <el-table-column property="backNumber" width="150" label="退货数量"></el-table-column>
      <el-table-column property="backMoney" width="150" label="退款金额"></el-table-column>
      <el-table-column property="createTime" width="200" label="创建时间"></el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
      @pagination="getList" />
  </div>
</template>
<script>
  import {
    fetchSaleorderList
  } from '@/api/sale'
  import {
    getCodeManager,
    codeToArray,
    getSellers
  } from '@/api/all'
  import Pagination from '@/components/Pagination'
  import {
    Message
  } from 'element-ui'
  export default {
    name: 'saleorderlist',
    components: {
      Pagination
    },
    data() {
      return {
        dataList: [],
        saleOrderStatus: [],
        sellers: [],
        total: 0,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 20,
          q_sellerId: '',
          q_buyName: '',
          q_saleState: ''
        },
        currentRow: null
      }
    },
    created() {
      getCodeManager('SALE_ORDER_STATE', () => {
        this.saleOrderStatus = codeToArray('SALE_ORDER_STATE');
      })
      getCodeManager('USE_YN', () => {})
      getSellers().then(res => {
        this.sellers = res.data.rows;
      })
      this.getList()
    },
    methods: {
      handleCurrentChange(val) {
        // 选中当前行数据
        this.currentRow = val
      },
      // 获取列表数据
      getList() {
        this.listLoading = true
        fetchSaleorderList(this.listQuery).then(response => {
          this.dataList = response.data.rows
          this.total = response.data.total
          this.listLoading = false
          console.log(this.dataList)
        })
      },
      handleFilter() {
        this.listQuery.page = 1
        this.getList()
      },
      check() {
        this.getList()
      },
      reset() {
        this.listQuery = {
          page: 1,
          limit: 20,
          q_sellerId: '',
          q_buyName: '',
          q_saleState: ''
        }
        this.getList()
      }
    }
  }
</script>
<style scoped>
  .filter-container .el-col-6 {
    margin-bottom: 15px;
  }

  .filter-item {
    margin-bottom: 0
  }

  /deep/ .filter-container label {
    font-size: 14px;
    font-weight: 500;
    margin-right: 10px;
  }
</style>
